/**
 * 
 */
package com.zhongkai.web.control.ticket;

import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhongkai.json.JSONObject;
import com.zhongkai.model.book.TDjCcdjxx;
import com.zhongkai.model.config.User;
import com.zhongkai.model.ticket.TPzJc;
import com.zhongkai.service.ticket.TicketDistributingService;
import com.zhongkai.tools.CheckWord;

/**
 * @packagename com.zhongkai.web.control.ticket
 * @filename TicketDistributingControl.java
 * @作者 吴嘉俊
 * @创建日期 Aug 8, 2011 2:22:23 PM
 *
 */
@Controller
public class TicketDistributingControl {
	private Logger log=Logger.getLogger(this.getClass());

	private TicketDistributingService ticketDistributingService;

	public TicketDistributingService getTicketDistributingService() {
		return ticketDistributingService;
	}
	@Resource
	public void setTicketDistributingService(
			TicketDistributingService ticketDistributingService) {
		this.ticketDistributingService = ticketDistributingService;
	}

	@RequestMapping(value="/system/ticket/ticket_distributing_fbu.do")
	public void findTicketsInfoByUser(String yprDm,HttpServletRequest request,HttpServletResponse response)throws Exception{
		PrintWriter out=response.getWriter();

		List listMyPzJc = ticketDistributingService.FindTicketsInfoByUser(yprDm);
		if (listMyPzJc==null || listMyPzJc.size()==0 ||listMyPzJc.isEmpty()){
			out.write("hasNoInfo");
		}
		else{
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("listMyPzJc", listMyPzJc);
			
			out.write(jsonObject.toString());
			System.out.println(jsonObject.toString());
		}
	}
	
	@RequestMapping(value="/system/ticket/ticket_distributing_fbt.do")
	public void findTicketsInfoByType(String pzzlDm,HttpServletRequest request,HttpServletResponse response)throws Exception{
		PrintWriter out=response.getWriter();
		
		List listPzJc = ticketDistributingService.FindTicketsInfoByType(pzzlDm);
		if (listPzJc==null || listPzJc.size()==0 ||listPzJc.isEmpty()){
			out.write("hasNoInfo");
		}
		else{
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("listPzJc", listPzJc);
			
			out.write(jsonObject.toString());
			System.out.println(jsonObject.toString());
		}
	}
	
	@RequestMapping(value="/system/ticket/ticket_distributing_save.do")
	public void save(HttpServletRequest request,HttpServletResponse response)throws Exception{
		PrintWriter out=response.getWriter();

		String[] yprDm = request.getParameterValues("hidyprDm");
		String[] pzzlDm = request.getParameterValues("hidpzzlDm");
		String[] zb = request.getParameterValues("hidzb");
		String[] sphmQ = request.getParameterValues("hidsphmQ");
		String[] sphmZ = request.getParameterValues("hidsphmZ");
		String[] sl = request.getParameterValues("hidsl");

		User admin =(User)request.getSession().getAttribute("user");
		
		ticketDistributingService.SaveAndUpdateTicketNum(yprDm,admin.getUserIdentifier(),pzzlDm,zb,sphmQ,sphmZ,sl);
		
		out.write(CheckWord.showMsg("税票分发成功！", "/system/ticket/ticket_distributing_form.jsp",request));
	}
	
	@RequestMapping(value="/system/ticket/ticket_distributing_AddZero.do")
	public void ticketNumAddZero(String TicketNumber,HttpServletRequest request,HttpServletResponse response)throws Exception{
		PrintWriter out=response.getWriter();

		out.write(ticketDistributingService.AddZero(Integer.parseInt(TicketNumber)));
	}
}
